<?php
class User_Model_Position 
{
 
	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new User_Model_DbTable_Position();
	}
	
	/**
	*add One Row  
	*@param array $row 
	*@return boolean
	*/
	public function add($row){
		return $this->_table->insert($row);
	}
	/**
	*Update One Row  
	*@param rowSet $row Customer's data 
	*@param int $customer_id 
	*@return boolean
	*/
	public  function update($row,$up_id){	
		$where = $this->_table->getAdapter()->quoteInto('up_id = ?', $up_id); 
		return $this->_table->update($row, $where);		
	}
			
	/**
	*Get Rowset By up_id
	*@param int $up_id 职位ID
	*@return Rowset
	*/
	public function getByUpid($id){
		$select = $this->_table->select()->where('up_id = ?', $id);	 
		return $this->_table->fetchRow($select)->toArray();	
	}
	
	
	public function getAll($order='up_level'){	
		$where = $this->_table->getAdapter()->quoteInto("?",1);		
		return $this->_table->fetchAll($where, $order)->toArray();
	}
	
	/**
	 * 根据条件获取指定模块信息
	 */
	public function getByCond($cond,$type,$order,$count=20, $offset=0){
		$table = $this->_table->info('name');
		$select = $this->_table->select()->from($table, $type);
		if(isset($cond['up_name']) && $cond['up_name']){
			$select->where('up_name = ?',$cond['up_name']);
		}
		if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }
        if ($count==0){        	
        	return $this->_table->fetchAll($select)->toArray(); 
        }
		$select->order($order);
		$select->limit($count,$offset);
		return $this->_table->fetchAll($select)->toArray();			
	}
	
   /**
	*Delete One Row
	*@param int $up_id
	*@return boolean
	*/
	public function delete($up_id){	
		$where = $this->_table->getAdapter()->quoteInto('up_id = ?', $up_id); 
		return $this->_table->delete($where);		
	}
	
}